package com.ibm.fn.qa.toccata.suite1;

import com.ibm.fn.qa.toccata.conf.TestData;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;

import junit.framework.TestCase;

/**
 * visit RESTful service and retrieve the data fields of a specified workflow.
 *
 * 
 */
public class TestWorkFlowProperty extends TestCase
{

	public void testDoesDataFieldExist() throws Exception
	{
	    String sampleWorkflowName = "HR Workflow";
	    String dataFieldName = "HomeAddress";
	    String dataFieldString = "\"paramName\":\"" + dataFieldName + "\"";
	    
        WebConversation wc = new WebConversation();
        WebRequest req = new GetMethodWebRequest(TestData.workflowResourceURL + sampleWorkflowName);
        WebResponse resp = wc.getResponse(req);
        
        assertEquals("Return content should be JSON format.", resp.getContentType().toLowerCase(), "application/json");
        assertEquals("Return code should be 200.", resp.getResponseCode(), 200);

        String responseText = resp.getText();
        //System.out.println(responseText);
        boolean theDataFieldExist = false;
        if(responseText.indexOf(dataFieldString) > 0)
            theDataFieldExist = true;

        assertTrue("The specified data field should be defined in workflow.", theDataFieldExist);
	}

}
